package com.uex.dev.manage.admin.vo.problem;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.uex.dev.manage.admin.enums.MaintainTypeEnum;
import com.uex.dev.manage.admin.po.MaintainPO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * @author lzs
 * @create 2024/03/01
 * @description
 */
@Schema(description = "问题维修记录及详情")
@Data
public class ProblemMaintainInfo {
    @Schema(description = "维修Id")
    private Integer id;
    @Schema(description = "问题ID列表")
    private List<Integer> maintainProblemIds;
    @Schema(description = "维修类别")
    private MaintainTypeEnum maintainType;
    @Schema(description = "维修类别描述")
    private String maintainTypeDesc;
    @Schema(description = "维修描述")
    private String maintainDesc;
    @Schema(description = "维修人")
    private String maintainUser;
    @Schema(description = "维修时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime maintainTime;
    @Schema(description = "维修差旅费")
    private Integer maintainTripCost;
    @Schema(description = "差旅费说明")
    private String maintainTripNote;
    @Schema(description = "更新部件费")
    private Integer maintainPartCost;
    @Schema(description = "部件费说明")
    private String maintainPartNote;

    public static ProblemMaintainInfo fromPO(MaintainPO maintainPO) {
        ProblemMaintainInfo problemMaintainResp = new ProblemMaintainInfo();
        BeanUtils.copyProperties(maintainPO, problemMaintainResp);
        problemMaintainResp.setMaintainTypeDesc(Objects.nonNull(maintainPO.getMaintainType()) ? maintainPO.getMaintainType().getDesc() : "-");
        return problemMaintainResp;
    }
}

